<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加速硬件性能基准可视化</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- DataTables CSS -->
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
</head>
<body>
    <!-- Header -->
    <nav class="navbar navbar-dark bg-primary">
        <div class="container-fluid">
            <span class="navbar-brand mb-0 h1">
                <i class="fas fa-chart-line"></i> 加速硬件性能基准可视化
            </span>
            <div>
                <button class="btn btn-light btn-sm me-2" onclick="uploadReport()">
                    <i class="fas fa-upload"></i> 上传报告
                </button>
                <button class="btn btn-success btn-sm" onclick="exportData()">
                    <i class="fas fa-download"></i> 导出对比
                </button>
            </div>
        </div>
    </nav>

    <!-- Main Container -->
    <div class="container-fluid mt-4">
        <!-- Control Panel -->
        <div class="row mb-3">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <label class="form-label"><strong>选择基准设备:</strong></label>
                                <select class="form-select" id="baselineSelect" onchange="updateBaseline()">
                                    <option value="">自动选择</option>
                                </select>
                                <small class="text-muted" id="currentBaselineInfo"></small>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label"><strong>选择模型:</strong></label>
                                <div id="modelFilters"></div>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label"><strong>已加载设备:</strong></label>
                                <div id="deviceList" class="small"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 1: Score Leaderboard -->
        <div class="row mb-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0"><i class="fas fa-trophy"></i> 综合评分排行榜</h5>
                    </div>
                    <div class="card-body">
                        <div id="loadingScores" class="text-center py-5">
                            <div class="spinner-border text-primary" role="status">
                                <span class="visually-hidden">加载中...</span>
                            </div>
                            <p class="mt-2">正在计算评分...</p>
                        </div>
                        <div id="scoreTable" style="display: none;">
                            <table class="table table-striped table-hover" id="scoresDataTable">
                                <thead>
                                    <tr>
                                        <th>排名</th>
                                        <th>设备名称</th>
                                        <th>总分</th>
                                        <th>性能得分</th>
                                        <th>能效得分</th>
                                        <th>资源得分</th>
                                        <th>稳定性得分</th>
                                    </tr>
                                </thead>
                                <tbody id="scoresTableBody">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 2 & 3: Radar Chart and Performance Comparison -->
        <div class="row mb-4">
            <div class="col-md-6">
                <div class="card h-100">
                    <div class="card-header bg-info text-white">
                        <h5 class="mb-0"><i class="fas fa-chart-radar"></i> 雷达图对比</h5>
                    </div>
                    <div class="card-body">
                        <canvas id="radarChart"></canvas>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card h-100">
                    <div class="card-header bg-success text-white">
                        <h5 class="mb-0"><i class="fas fa-chart-bar"></i> 性能对比</h5>
                    </div>
                    <div class="card-body">
                        <ul class="nav nav-tabs" id="perfTabs" role="tablist">
                            <li class="nav-item" role="presentation">
                                <button class="nav-link active" id="qps-tab" data-bs-toggle="tab" data-bs-target="#qps-pane" type="button">QPS</button>
                            </li>
                            <li class="nav-item" role="presentation">
                                <button class="nav-link" id="latency-tab" data-bs-toggle="tab" data-bs-target="#latency-pane" type="button">延迟</button>
                            </li>
                        </ul>
                        <div class="tab-content mt-3" id="perfTabContent">
                            <div class="tab-pane fade show active" id="qps-pane">
                                <canvas id="qpsChart"></canvas>
                            </div>
                            <div class="tab-pane fade" id="latency-pane">
                                <canvas id="latencyChart"></canvas>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 4: Detailed Metrics Table -->
        <div class="row mb-4">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-warning text-dark">
                        <h5 class="mb-0"><i class="fas fa-table"></i> 详细指标对比表</h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-bordered" id="detailsTable">
                                <thead>
                                    <tr id="detailsTableHeader">
                                        <th>指标</th>
                                    </tr>
                                </thead>
                                <tbody id="detailsTableBody">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 5: Power Analysis -->
        <div class="row mb-4">
            <div class="col-md-6">
                <div class="card h-100">
                    <div class="card-header bg-danger text-white">
                        <h5 class="mb-0"><i class="fas fa-bolt"></i> 能耗分析</h5>
                    </div>
                    <div class="card-body">
                        <canvas id="powerChart"></canvas>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card h-100">
                    <div class="card-header bg-secondary text-white">
                        <h5 class="mb-0"><i class="fas fa-chart-line"></i> 能效排名</h5>
                    </div>
                    <div class="card-body">
                        <canvas id="efficiencyChart"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Upload Modal -->
    <div class="modal fade" id="uploadModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">上传评测报告</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <input type="file" class="form-control" id="fileInput" accept=".json">
                    <div class="mt-3" id="uploadStatus"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="submitUpload()">上传</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Device Details Modal -->
    <div class="modal fade" id="deviceDetailsModal" tabindex="-1" aria-labelledby="deviceModalTitle" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-scrollable">
            <div class="modal-content">
                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title" id="deviceModalTitle">
                        <i class="fas fa-server"></i> 设备详情
                    </h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body" id="deviceModalBody">
                    <!-- Content will be dynamically loaded by JavaScript -->
                    <div class="text-center py-5">
                        <div class="spinner-border text-primary" role="status">
                            <span class="visually-hidden">加载中...</span>
                        </div>
                        <p class="mt-2">正在加载设备信息...</p>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                        <i class="fas fa-times"></i> 关闭
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- DataTables JS -->
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
    <!-- Custom JS -->
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>
    <script src="{{ url_for('static', filename='js/charts.js') }}"></script>
    
    <script>
        // Initialize on page load
        $(document).ready(function() {
            loadReports();
        });
    </script>
</body>
</html>

